package com.ship.common.core.mybatis.mapping;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ship.common.core.base.PageBean;
import com.ship.common.core.utils.StringUtil;

import java.lang.reflect.Field;

/**
 * @author 31463
 */
public class StringMapping extends BaseMapping {

    @Override
    public void apply(Object root, Field field, QueryWrapper queryWrapper) {
        Object value = getValue(root, field);
        if (value != null) {
            queryWrapper.like(StringUtil.humpToUnderline(field.getName()), value);
        }
    }

    @Override
    public <T extends PageBean> void applyList(Object root, Field field, QueryWrapper<T> queryWrapper, String keyName) {
        Object value = getValue(root, field);
        if (value != null) {
            queryWrapper.in(keyName, value);
        }
    }
}
